package com.recruit.g1.job.mapper;

import com.recruit.g1.pojo.job.entity.Job;
import com.recruit.g1.pojo.job.vo.JobListVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface JobMapper {

    @Insert("INSERT INTO job(city_id,company_id,job_name,title,description,requirements,salary_range,location,post_time,status)" +
            "  VALUES (#{cityId},#{companyId},#{jobName},#{title},#{description},#{requirements},#{salaryRange},#{location},#{postTime},#{status})")
    void insertJob(Job job);

    /*@Select(" SELECT id,  job_name,   title, description,  requirements, salary_range, Location, post_time, city_id  FROM job  <where> " +
            " <if test='jobName!=\'\' and jobName!=null'>" +
            "  job_name LIKE CONCAT('%',#{jobName},'%')" +
            " </if>" +
            " <if test='cityId!=null'>" +
            " AND city_id = #{cityId}" +
            " </if>   </where>")*/
    @Select("<script>SELECT id, job_name, title, description, requirements, salary_range, `Location`, post_time, city_id " +
            " FROM job " +
            " <where> " +
            "   <if test='jobName != null and jobName != \"\"'> " +
            "       job_name LIKE CONCAT('%', #{jobName}, '%') " +
            "   </if> " +
            "   <if test='cityId != null'> " +
            "       AND city_id = #{cityId} " +
            "   </if> " +
            " </where></script>")
    List<JobListVO> jobList(@Param("jobName") String jobname,
//                          @Param("userid") Long userid,
                            @Param("cityId") Long cityid
    );
    @Delete("DELETE   FROM job  WHERE id = #{id}")
    int deleteJob( @Param("id") Integer id );
}